package org.example.intecepter;

import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

//        String requestURI = request.getRequestURI();
//        StringBuffer requestURL = request.getRequestURL();
//        System.out.println(requestURI);

        HttpSession session = request.getSession();
        Object empSession = session.getAttribute("empSession");
        if(empSession == null){
            response.sendRedirect("/forward/toLogin");
            return false;
        }
        return true;
    }
}
